package com.bw.announcement.announcement

import android.content.res.ColorStateList
import android.graphics.Color
import android.widget.TextView
import com.bw.announcement.R
import com.bw.announcement.entity.AnnouncementData
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class AnnouncementAdapter : BaseQuickAdapter<AnnouncementData, BaseViewHolder>(R.layout.notice_item){
    override fun convert(holder: BaseViewHolder, item: AnnouncementData) {
        // 设置标题
        holder.setText(R.id.tv_title, item.title)

        // 设置内容
        holder.setText(R.id.tv_content, item.content)

        // 设置时间，如果publishTime为空则显示"周一"
        val timeText = if (item.publishTime.isNullOrEmpty()) "周一" else item.publishTime
        holder.setText(R.id.tv_pushtime, timeText)

        // 设置标签文本和颜色
        val tvTag = holder.getView<TextView>(R.id.tv_tag)

        // 优先级1：如果title包含"活动"，设置为"立即报名"
        if (item.title.contains("活动")) {
            tvTag.text = "立即报名"
            // 保持默认颜色（蓝色背景+白色文字）
            tvTag.backgroundTintList = ColorStateList.valueOf(Color.parseColor("#4086F4"))
            tvTag.setTextColor(Color.WHITE)
        } else {
            // 优先级2：根据status设置标签
            tvTag.text = item.status

            // 如果是未读状态，设置特殊颜色
            if (item.status == "未读") {
                tvTag.backgroundTintList = ColorStateList.valueOf(Color.parseColor("#DBEAFE"))
                tvTag.setTextColor(Color.parseColor("#4086F4"))
            } else {
                // 保持默认颜色
                tvTag.backgroundTintList = ColorStateList.valueOf(Color.parseColor("#4086F4"))
                tvTag.setTextColor(Color.WHITE)
            }
        }

    }
}